/*
   file : mult_test.c
   Unversity of Jiangsu
   memoryDB      2010.6
 */



#include"api.h"
#include<pthread.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>


void *_sql(void *send)
{
	int sockfd=sql_connect(IP_ADD,PORT);
	if(sockfd < 0){
		printf("connect error\n");
		return;
	}
	sql_exec((char *)send,strlen((char *)send),sockfd);
	return;
}

int main()
{
	pthread_t n[4];
	char *s1="select * from list where call_id<\"1000454\" and switch_type=22;";
	char *d1="delete from list;";
	char *u1="update list set switch_type=55;";
	
	int i;
	int m[4];
	for(i=0;i!=4;i++){
		srand((unsigned)time(NULL));
		sleep(2);
		m[i] = rand()%3;
		
	}

 	for(i=0;i!=4;i++){
		if(m[i] == 0)
			pthread_create(n+i,NULL,_sql,s1);
		else if(m[i] == 1)
			pthread_create(n+i,NULL,_sql,d1);
		else
			pthread_create(n+i,NULL,_sql,u1);
		
	}

	for(i=0;i!=4;i++){
		pthread_join(n[i],NULL);
	}

	return 0;
}
